<?php
session_start();

//require_once("includes/connect.php");
//require_once("includes/function.php");


$db = NEW myDBS();
//$db->selectDB("account");

//$sql = "SELECT DISTINCT tbl_pet.*, panngan2_name, panngan3_name, expenses1_name, expenses2_name
//			FROM tbl_pet, panngan2, panngan3, expenses_lvl1, expenses_lvl2
//			WHERE lvl1_id = '" . $_SESSION["lvl1_id"] . "'
//			AND tbl_pet.panngan2_id = panngan2.panngan2_id
//			AND tbl_pet.panngan3_id = panngan3.panngan3_id
//			AND tbl_pet.ex1_id = expenses_lvl1.expenses1_id
//			AND tbl_pet.ex2_id = expenses_lvl2.expenses2_id
//			ORDER BY pet_id
//			";

$sql = "SELECT * "
        . " FROM tbl_petition, expenses_lvl1, expenses_lvl2 "
        . " WHERE lvl1_id = '" . $_SESSION["lvl1_id"] . "'"
        . " AND tbl_petition.ex1_id = expenses_lvl1.expenses1_id "
        . " AND tbl_petition.ex2_id = expenses_lvl2.expenses2_id "
        . " ORDER BY p_id";
//echo $sql;
$result = $db->runSQL($sql);
//$rows = $db1->fetch_object($result);
?>

<script type="text/javascript">
    $(document).ready(function() {
        $("#example").dataTable();

    });

    function edit(utility_id) {
        //alert("adfs");
        $('<div>').dialog2({
            autoOpen: true,
            title: "แก้ไขฎีกา",
            content: "dlg_add_pet.php?utility_id=" + utility_id,
            id: "modal-chkJob"
        });

    }

    function del(utility_id) {
        //alert("adfs");
        if (confirm("คุณแน่ใจที่ต้องการลบรายการนี้ใช่ไหม?"))
        {
            $.post("process_utility.php", {utility_id: utility_id, task: 'del'}, function() {
                window.location.href = "index.php?pages=frm_petition_utility&pageid=9";
            });
        }

    }

    function cancel(id) {
        if (confirm("คุณแน่ใจใช่ไหมที่ต้องการ ยกเลิก สัญญานี้")) {

            $('<div>').dialog2({
                autoOpen: true,
                title: "ยกเลิกฎีกา",
                content: "dlg_cancel.php?tblname=tbl_pet&id=" + id,
                id: "modal-cancel"
            });
        }
    }


</script>


<a class="btn btn-primary" href="index.php?pages=vProject">เพิ่มฎีกา</a>
<table id="example" class="table table-bordered" width="100%" >
    <caption><br></caption>
    <thead>
        <tr>
            <th>#</th>
            <th>เลขที่ฎีกา</th>
            <th>แผนงาน</th>
            <th>งาน</th>
            <th>หมวด</th>
            <th>ประเภท</th>
            <th>จำนวนเงิน</th>
            <th>action</th>
        </tr>
    </thead>
    <tbody>	
        <?php
        $i = 0;
        while ($rows = $db->fetch_object($result)) {
            $i++;

            echo "<tr>
                    <td>$i</td>
                    <td>$rows->p_id</td>
                    <td>$rows->panngan2_name</td>
                    <td>$rows->panngan3_name</td>
                    <td>$rows->expenses1_name</td>
                    <td>$rows->expenses2_name</td>
                    <td>" . number_format($rows->inpNet, 2) . "</td>
                    <td><a href='index.php?pages=frmEditPetition1&petition_id=$rows->petition_id'><i class='icon-pencil'></i></a>&nbsp;|&nbsp;<a href='javascript:cancel($rows->id)'><i class='icon-remove'></i></a>&nbsp;|&nbsp;<a href='prtPetition1.php?petition_id=$rows->petition_id' target='_blank'><i class='icon-print'></i></a></td>
            </tr>
            ";
        }
        ?>

    </tbody>
</table>
